
AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

function ENT:SetPlayer(ply)

	if ply == nil then self:Remove() end

	self:SetVar( "Founder", ply )
	self:SetPhysicsAttacker(ply)
	self:SetOwner(ply)
    self:SetVar( "FounderIndex", ply:UniqueID() )
    
    self:SetNetworkedString( "FounderName", ply:Nick() )
	//print(self:GetNetworkedString( "FounderName" ))

end

function ENT:Setup(model,color)
	
	if self:GetOwner() == nil then return end
	
	self.Model = model
	self.Color = color 
	
end

function ENT:GetSpecifics() //obsolete

	local tbl = {
	self.Health,
	self.Model}

return tbl end

function ENT:Initialize()

	self:SetModel( self.Model )
	self:SetColor( self.Color.r,self.Color.g,self.Color.b,self.Color.a )
	
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS )
	
	self.Crash = false
	
end

function ENT:PhysicsSimulate(phys, frametime)
	phys:Wake()
end

function ENT:Think()
	if self.Crash then
		if self:GetOwner():IsValid() then
			self:GetOwner():DestroyVehicle(nil)
		end
	end
end 

function ENT:OnTakeDamage(dmg)
	if dmg:GetAttacker():IsPlayer() then
		if (dmg:GetAttacker():Team() == self:GetOwner():Team()) then
			return
		end
	end
	if dmg:GetAttacker() and !dmg:IsExplosionDamage() then
		util.BlastDamage( dmg:GetAttacker(), dmg:GetAttacker(), self:GetOwner():GetVehicle():GetPos(), 20, dmg:GetDamage() )
	end
end 

function ENT:Destroy()
	self:Remove()
end

function ENT:PhysicsCollide( data, physobj )
	if (data.Speed > 2200 && data.DeltaTime > 0.2 ) then
		if self:GetOwner() and self:GetOwner():IsValid() then
			self.Crash = true
		end
	end
end